//
//  LoadingView.m
//  SEOBox
//
//  Created by Syd on 10-3-1.
//  Copyright 2010 MusicPeace.ORG. All rights reserved.
//

#import "LoadingView.h"


@implementation LoadingView

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setHidden:YES];
        [self setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable|NSViewMaxXMargin|NSViewMaxYMargin|NSViewMinXMargin|NSViewMinYMargin];
    }
    return self;
}

- (void)drawRect:(NSRect)rect {
    NSColor *bgColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.95f];
    [bgColor set];
    NSRectFill(self.bounds);
    [super drawRect:rect];
}

- (void)startAnimating:(id)sender {
    NSProgressIndicator *progressView = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(CGRectGetWidth(self.frame)/2-16, CGRectGetHeight(self.frame)/2-16, 32.0f,32.0f)];
    [progressView setAutoresizingMask:NSViewMaxXMargin|NSViewMaxYMargin|NSViewMinXMargin|NSViewMinYMargin];
    [progressView startAnimation:nil];
    [progressView setStyle: NSProgressIndicatorSpinningStyle];
    [progressView setControlSize: NSRegularControlSize];
    [self addSubview:progressView];
    [progressView release];
    [self setHidden:NO];
}

- (void)stopAnimation:(id)sender {
    [self setHidden:YES];
    NSView *view;
    for (view in [self subviews])
    {
        if ([view isKindOfClass:[NSProgressIndicator class]]) {
            [view removeFromSuperview];
        }
    }
}
@end
